package com.jumi.microservice.service;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.rocketmq.RocketMqConfig;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
@DubboService
public class rocketMqServiceImpl implements IRocketMqService {
    @Resource
    ProducerBean producerBean;
    @Autowired
    RocketMqConfig rocketMqConfig;

    public ResponseResult message(String message) {
        byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
        Message msg = new Message(rocketMqConfig.getTopic(), rocketMqConfig.getTag(), "", bytes);
        producerBean.send(msg);
        return ResponseResult.success();
    }
}
